package com.grudesign.stutrip.controller;


import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Vo.userInfoVo;
import com.grudesign.stutrip.entity.Vo.userQueryVo;
import com.grudesign.stutrip.service.userInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 普通用户表 前端控制器
 * </p>
 *
 * @author wx
 * @since 2022-04-14
 */
@RestController
public class userInfoController {

    @Autowired
    private userInfoService userInfoService;

    /**
     * 登录
     *
     * @param reqVo 入参
     * @return
     */
    @PostMapping("/login")
    public Object login(@RequestBody userInfoVo reqVo) {
        Object obj = userInfoService.login(reqVo);
        return obj;
    }

    /**
     * 注册
     *
     * @param reqVo
     * @return
     */
    @PostMapping("/register")
    public Object register(@RequestBody userInfoVo reqVo) {
        Object obj = userInfoService.register(reqVo);
        return obj;
    }

    /**
     * 验证码发送
     *
     * @param phone
     * @return
     */
    @GetMapping("/sendCheckCode/{phone}")
    public Object sendCheckCode(@PathVariable String phone) {
        Object obj = userInfoService.sendCheckCode(phone);
        return obj;
    }


    @PostMapping("/queryUsers/{page}/{next}")
    public Object conditionQueryUserInfo(@PathVariable("page") long page,
                                         @PathVariable("next") long next,
                                         @RequestBody(required = false) userQueryVo queryVo) {
        Object obj = userInfoService.getQueryUsers(page,next,queryVo);
        return obj;
    }

    @DeleteMapping("delUser")
    public Object deleteUser(@RequestParam String id) {
        userInfoService.removeById(id);
        return new ReturnInfo("200", "ok");
    }

}

